//****************************************************************
//* Copyright (c) 2004 Ford Motor Company. All Rights Reserved.
//*
//* $$Workfile:   SFIFindQuery.java  $$
//* $$Revision:   1.0  $$
//* $$Author:   aponte  $$
//* $$Date:   Dec 10 2008 11:00:04  $$
//*
//*****************************************************************
package ar.com.ford.it.fullEconomics.persistence.dao.query;

import java.sql.Timestamp;
import oracle.toplink.expressions.Expression;
import oracle.toplink.expressions.ExpressionBuilder;
import ar.com.ford.it.fullEconomics.persistence.dto.Ncas003ColorVw;
import ar.com.ford.it.fullEconomics.persistence.dto.Ncas012VehicleVw;
import com.ford.it.persistence.impl.toplink.CustomExpressionFactory;

public class SFIFindQuery implements CustomExpressionFactory {

	public Expression createExpression(ExpressionBuilder builder,
			Object[] parameters) {

		Timestamp fechaInicio = (Timestamp) parameters[0];
		Timestamp fechaFin = (Timestamp) parameters[1];
		Ncas012VehicleVw ncas012VehicleVw = (Ncas012VehicleVw) parameters[2];
		Ncas003ColorVw ncas003ColorVw = (Ncas003ColorVw) parameters[3];

		Expression exp = null;

		exp = builder.get("cas104VehicleCodeC").equal(ncas012VehicleVw);

		exp = exp.and(builder.get("cas104ColorCodeC").equal(ncas003ColorVw).or(
				builder.get("cas104ColorCodeC").equal(null)));

		exp = exp.and(builder.get("cas104SfiInDateY").lessThan(fechaInicio));

		exp = exp.and(builder.get("cas104SfiOutDateY").greaterThan(fechaFin));

		return exp;
	}

}
